package public

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"woo-server/controllers"
	"woo-server/services/public"
)

// @tags 权限
// @summary 登录code转登录态
// @Description 登录code转登录态
// @Accept json
// @Param code path string false "企业微信code"
// @Success 200 {string} json "{"StatusCode":200,"IsEncrypted":false,"Data":""}"
// @Router /api/login [get]
func Login(c *gin.Context) {
	// 入参
	code := c.Query("VerifyCode")
	codeKey := c.Query("key")
	username := c.Query("username")
	password := c.Query("password")
	// common
	com := controllers.NewCommon(c, "Login")

	// 生成登录态
	LoginService := public.NewLoginService(com)
	result := LoginService.Login(c, username, password, codeKey, code)

	// 返回
	c.JSON(http.StatusOK, result)
}

func Logout(c *gin.Context) {
	com := controllers.NewCommon(c, "Logout")
	LoginService := public.NewLoginService(com)
	result := LoginService.Logout(c)
	c.JSON(http.StatusOK, result)
}
